package cn.xp.web;

import cn.xp.domain.Order;
import cn.xp.domain.User;
import cn.xp.feign.UserFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description 订单服务接口
 * @Author xp
 * @Date 2023/4/14 11:47
 * @Version 1.0
 */
@RestController
@RequestMapping("/order")
public class OrderController {
    /**
     * feign调用user服务的客户端组件
     */
    @Autowired
    private UserFeignClient feignClient;

    /**
     * 调用user服务接口并返回
     * @param id 用户id
     * @return
     */
    @GetMapping("/{id}")
    public Order getById(@PathVariable("id") Long id){
        //1.查询order
        Order order = new Order(3l, "order的接口");
        //2.调用feign查询user
        User user = feignClient.getById(1l);
        //3.把查询的user放进order
        order.setUser(user);
        //4.返回order
        return order;
    }
}